<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>Aria: gyroExample.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Aria
   &#160;<span id="projectnumber">2.9.4</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('gyroExample_8cpp-example.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">gyroExample.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>Example program that activates an onboard gyro if it exists and uses its data to correct the robot pose.This program uses <a class="el" href="classArActionKeydrive.html" title="This action will use the keyboard arrow keys for input to drive the robot. ">ArActionKeydrive</a> and <a class="el" href="classArActionJoydrive.html" title="This action will use the joystick for input to drive the robot. ">ArActionJoydrive</a> to allow teleoperation with the keyboard or joystick, and displays gyro data. Additional keys (numbers 0-9 and letters q, w, e, r, t, y, u, i, o, p) activate preset rotation velocities.</p>
<div class="fragment"><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;Aria.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;ArAnalogGyro.h&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">class </span>GyroTask</div><div class="line">{</div><div class="line"><span class="keyword">public</span>:</div><div class="line">  <span class="comment">// the constructor, it must use constructor chaining to intialize its base</span></div><div class="line">  <span class="comment">// class ArSimpleUserTask</span></div><div class="line">  GyroTask(<a name="_a0"></a><a class="code" href="classArRobot.html">ArRobot</a> *robot);</div><div class="line">  <span class="comment">// empty destructor</span></div><div class="line">  ~GyroTask(<span class="keywordtype">void</span>) {}</div><div class="line">  </div><div class="line">  <span class="comment">// the task we want to do</span></div><div class="line">  <span class="keywordtype">void</span> doTask(<span class="keywordtype">void</span>);</div><div class="line"></div><div class="line">  <span class="keywordtype">bool</span> handlePacket(<a name="_a1"></a><a class="code" href="classArRobotPacket.html">ArRobotPacket</a> *pkt);</div><div class="line"><span class="keyword">protected</span>:</div><div class="line">  <span class="comment">//double myHeading;</span></div><div class="line">  <a name="_a2"></a><a class="code" href="classArAnalogGyro.html">ArAnalogGyro</a> *myGyro;</div><div class="line">  <a class="code" href="classArRobot.html">ArRobot</a> *myRobot;</div><div class="line">  <a name="_a3"></a><a class="code" href="classArFunctorC.html">ArFunctorC&lt;GyroTask&gt;</a> myTaskCB;</div><div class="line">  <a name="_a4"></a><a class="code" href="classArRetFunctor1C.html">ArRetFunctor1C&lt;bool, GyroTask, ArRobotPacket*&gt;</a> myPacketHandlerCB;</div><div class="line">  <span class="keywordtype">bool</span> gotGyroPacket;</div><div class="line">};</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// the constructor, note how it uses chaining to initialize the myTaskCB</span></div><div class="line">GyroTask::GyroTask(<a class="code" href="classArRobot.html">ArRobot</a> *robot) :</div><div class="line">  myTaskCB(<span class="keyword">this</span>, &amp;GyroTask::doTask),</div><div class="line">  myPacketHandlerCB(<span class="keyword">this</span>, &amp;GyroTask::handlePacket),</div><div class="line">  gotGyroPacket(<span class="keyword">false</span>)</div><div class="line">{</div><div class="line">  <a name="_a5"></a><a class="code" href="classArKeyHandler.html">ArKeyHandler</a> *keyHandler;</div><div class="line">  myRobot = robot;</div><div class="line">  <span class="comment">// just add it to the robot</span></div><div class="line">  myRobot-&gt;<a name="a6"></a><a class="code" href="classArRobot.html#a50070f4e19b91aaac20772d15d9ad805">addUserTask</a>(<span class="stringliteral">&quot;GyroTask&quot;</span>, 50, &amp;myTaskCB);</div><div class="line">  myRobot-&gt;addPacketHandler(&amp;myPacketHandlerCB, <a name="a7"></a><a class="code" href="classArListPos.html#adb42d52c70a646c5698c5513cd25bbd0a3c55111fa6c7f63c41fc0b387f5b57d9">ArListPos::LAST</a>);</div><div class="line">  myRobot-&gt;comInt(<a name="a8"></a><a class="code" href="classArCommands.html#a9a31f904a95bbc31d8b33c6637100cc4a4f783f34029e95605207be5aad66f130">ArCommands::GYRO</a>, 2);</div><div class="line">  myGyro = <span class="keyword">new</span> <a class="code" href="classArAnalogGyro.html">ArAnalogGyro</a>(myRobot);</div><div class="line">  <span class="keywordflow">if</span> ((keyHandler = <a name="a9"></a><a class="code" href="classAria.html#a5b8042b38b19d6a5d3cfbed4df483e67">Aria::getKeyHandler</a>()) == NULL)</div><div class="line">  {</div><div class="line">    keyHandler = <span class="keyword">new</span> <a class="code" href="classArKeyHandler.html">ArKeyHandler</a>;</div><div class="line">    <a name="a10"></a><a class="code" href="classAria.html#a9e5496a4ec2c379c8e18706922b57cc1">Aria::setKeyHandler</a>(keyHandler);</div><div class="line">    <span class="keywordflow">if</span> (myRobot != NULL)</div><div class="line">      myRobot-&gt;attachKeyHandler(keyHandler);</div><div class="line">    <span class="keywordflow">else</span></div><div class="line">      <a name="a11"></a><a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a name="a12"></a><a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;GyroTask: No robot to attach a keyHandler to, keyHandling won&#39;t work... either make your own keyHandler and drive it yourself, make a keyhandler and attach it to a robot, or give this a robot to attach to.&quot;</span>);</div><div class="line">  }  </div><div class="line">  keyHandler-&gt;<a name="a13"></a><a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;1&#39;</span>, <span class="keyword">new</span> <a name="_a14"></a><a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a name="a15"></a><a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, 10));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;2&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, 20));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;3&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, 30));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;4&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, 40));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;5&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, 50));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;6&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, 60));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;7&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, 70));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;8&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, 80));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;9&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, 90));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;0&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, 100));</div><div class="line"></div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;q&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, -10));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;w&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, -20));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;e&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, -30));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;r&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, -40));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;t&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, -50));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;y&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, -60));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;u&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, -70));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;i&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, -80));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;o&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot,&amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, -90));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;p&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot, &amp;<a class="code" href="group__easy.html#ga613157de1936d0c34ed73e32787ae661">ArRobot::setRotVel</a>, -100));</div><div class="line"></div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;a&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot, &amp;<a name="a16"></a><a class="code" href="group__easy.html#gafbbe47b4351cc9baf2559d188803ee72">ArRobot::setHeading</a>, 0));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;s&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot, &amp;<a class="code" href="group__easy.html#gafbbe47b4351cc9baf2559d188803ee72">ArRobot::setHeading</a>, 90));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;d&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot, &amp;<a class="code" href="group__easy.html#gafbbe47b4351cc9baf2559d188803ee72">ArRobot::setHeading</a>, 180));</div><div class="line">  keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;f&#39;</span>, <span class="keyword">new</span> <a class="code" href="classArFunctor1C.html">ArFunctor1C&lt;ArRobot, double&gt;</a>(myRobot, &amp;<a class="code" href="group__easy.html#gafbbe47b4351cc9baf2559d188803ee72">ArRobot::setHeading</a>, 270));</div><div class="line"></div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> GyroTask::doTask(<span class="keywordtype">void</span>)</div><div class="line">{</div><div class="line">  <span class="comment">/*</span></div><div class="line"><span class="comment">  double degrees = -((myRobot-&gt;getAnalog() * 5.0 / 255) - 2.509) * 150 / 2.5 * 1.265;</span></div><div class="line"><span class="comment">  if (fabs(degrees) &lt; 2)</span></div><div class="line"><span class="comment">    degrees = 0;</span></div><div class="line"><span class="comment">  myHeading += degrees * .025;</span></div><div class="line"><span class="comment">  printf(&quot;%10f %10f %10f %10f\n&quot;, myRobot-&gt;getAnalog() * 5.0 / 255, degrees,</span></div><div class="line"><span class="comment">     myRobot-&gt;getRotVel(), myHeading);</span></div><div class="line"><span class="comment">  fflush(stdout);</span></div><div class="line"><span class="comment">  */</span></div><div class="line">  printf(<span class="stringliteral">&quot;gyro th (mode 1 only):%8.4f  encoder th:%8.4f   ArRobot mixed th:%8.4f  temp:%d  ave:%g  gyro packets:%s\n&quot;</span>, myGyro-&gt;getHeading(), myRobot-&gt;getRawEncoderPose().getTh(), myRobot-&gt;getTh(), myGyro-&gt;getTemperature(), myGyro-&gt;getAverage(), gotGyroPacket?<span class="stringliteral">&quot;received&quot;</span>:<span class="stringliteral">&quot;not received&quot;</span>);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">bool</span> GyroTask::handlePacket(<a class="code" href="classArRobotPacket.html">ArRobotPacket</a> *pkt)</div><div class="line">{</div><div class="line">    <span class="keywordflow">if</span>(pkt-&gt;<a name="a17"></a><a class="code" href="classArRobotPacket.html#a0e41b0bbe73260cff302094500a51b7d">getID</a>() == 152) </div><div class="line">        gotGyroPacket = <span class="keyword">true</span>;</div><div class="line">    <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div><div class="line">{</div><div class="line">  <a name="a18"></a><a class="code" href="classAria.html#ad99c16b5d947229d9f8e1c5b2d4cdd73">Aria::init</a>();</div><div class="line">  <a class="code" href="classArRobot.html">ArRobot</a> robot;</div><div class="line">  </div><div class="line">  <span class="comment">// the joydrive action</span></div><div class="line">  <a name="_a19"></a><a class="code" href="classArActionJoydrive.html">ArActionJoydrive</a> joydriveAct;</div><div class="line">  <span class="comment">// the keydrive action</span></div><div class="line">  <a name="_a20"></a><a class="code" href="classArActionKeydrive.html">ArActionKeydrive</a> keydriveAct;</div><div class="line"></div><div class="line">  GyroTask gyro(&amp;robot);</div><div class="line"></div><div class="line">  <span class="comment">// sonar device, so the limiter will work, this must be added to the robot</span></div><div class="line">  <a name="_a21"></a><a class="code" href="classArSonarDevice.html">ArSonarDevice</a> sonar;</div><div class="line"></div><div class="line">  <a name="_a22"></a><a class="code" href="classArArgumentParser.html">ArArgumentParser</a> parser(&amp;argc, argv);</div><div class="line">  parser.<a name="a23"></a><a class="code" href="classArArgumentParser.html#a501694b62a7f8b0c3cadd84aeafe1b35">loadDefaultArguments</a>();</div><div class="line">  <a name="_a24"></a><a class="code" href="classArRobotConnector.html">ArRobotConnector</a> connector(&amp;parser, &amp;robot);</div><div class="line">  <span class="keywordflow">if</span> (!<a name="a25"></a><a class="code" href="classAria.html#a1b090c01d88bb420b8cf8e0384d25ee1">Aria::parseArgs</a>() || argc &gt; 1)</div><div class="line">  {</div><div class="line">    <a name="a26"></a><a class="code" href="classAria.html#a10d71f3d4d0cf7f38c58a1f749f64a42">Aria::logOptions</a>();</div><div class="line">    <a name="a27"></a><a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(1);</div><div class="line">    <span class="keywordflow">return</span> 1;</div><div class="line">  }</div><div class="line">  </div><div class="line"></div><div class="line">  printf(<span class="stringliteral">&quot;This program will allow you to use a joystick or keyboard to control the robot.\nYou can use the arrow keys to drive, and the spacebar to stop.\nFor joystick control press the trigger button and then drive.\nPress escape to exit.\n&quot;</span>);</div><div class="line"></div><div class="line"></div><div class="line">  <span class="comment">// if we don&#39;t have a joystick, let &#39;em know</span></div><div class="line">  <span class="keywordflow">if</span> (!joydriveAct.<a name="a28"></a><a class="code" href="classArActionJoydrive.html#aadc5a4816e3c69bb0c7b57f72bbadde5">joystickInited</a>())</div><div class="line">    printf(<span class="stringliteral">&quot;Do not have a joystick, only the arrow keys on the keyboard will work.\n&quot;</span>);</div><div class="line">  </div><div class="line">  <span class="comment">// set the joystick so it won&#39;t do anything if the button isn&#39;t pressed</span></div><div class="line">  joydriveAct.<a name="a29"></a><a class="code" href="classArActionJoydrive.html#a2d2e8053a6a49487c5dbeadcbcc44556">setStopIfNoButtonPressed</a>(<span class="keyword">false</span>);</div><div class="line"></div><div class="line">  <span class="comment">// add the sonar to the robot</span></div><div class="line">  robot.<a name="a30"></a><a class="code" href="classArRobot.html#a97d57b28549fdef851c00749a97cc776">addRangeDevice</a>(&amp;sonar);</div><div class="line"></div><div class="line">  <span class="comment">// try to connect, if we fail exit</span></div><div class="line">  <span class="keywordflow">if</span> (!connector.<a name="a31"></a><a class="code" href="classArRobotConnector.html#ab192ac393d9cc1e5b61b1a82b08d085d">connectRobot</a>())</div><div class="line">  {</div><div class="line">    printf(<span class="stringliteral">&quot;Could not connect to robot... exiting\n&quot;</span>);</div><div class="line">    <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(1);</div><div class="line">    <span class="keywordflow">return</span> 1;</div><div class="line">  }</div><div class="line"></div><div class="line">  robot.<a name="a32"></a><a class="code" href="classArRobot.html#aceef80a6274fb34aafcc422e4b1778c1">comInt</a>(<a name="a33"></a><a class="code" href="classArCommands.html#a9a31f904a95bbc31d8b33c6637100cc4aa8d799cced5def80525936119963aad4">ArCommands::ENABLE</a>, 1);</div><div class="line"></div><div class="line">  robot.<a name="a34"></a><a class="code" href="group__easy.html#ga9ab030786d423237d3e4aa06c0e9d8ce">addAction</a>(&amp;joydriveAct, 50);</div><div class="line">  robot.<a class="code" href="group__easy.html#ga9ab030786d423237d3e4aa06c0e9d8ce">addAction</a>(&amp;keydriveAct, 45);</div><div class="line"></div><div class="line">  <span class="comment">// set the joydrive action so it&#39;ll let the keydrive action fire if</span></div><div class="line">  <span class="comment">// there is no button pressed</span></div><div class="line">  joydriveAct.<a class="code" href="classArActionJoydrive.html#a2d2e8053a6a49487c5dbeadcbcc44556">setStopIfNoButtonPressed</a>(<span class="keyword">false</span>);</div><div class="line"></div><div class="line">  </div><div class="line">  <span class="comment">// run the robot, true here so that the run will exit if connection lost</span></div><div class="line">  robot.<a name="a35"></a><a class="code" href="classArRobot.html#a3c1c3056633caf455c8265259f57f6d7">run</a>(<span class="keyword">true</span>);</div><div class="line">  </div><div class="line">  <span class="comment">// now exit</span></div><div class="line">  <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(0);</div><div class="line">  <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
